home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / cli / master60.zoo / master / source / index.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-23  |  1.9 KB  |  106 lines

  1. #include    <stdio.h>
  2. #include    <ctype.h>
  3.  
  4. #define    MAXLINE    256
  5. #define REG    register
  6.  
  7. main(argc,argv)
  8. char **argv ;
  9. {
  10.   char    *infile = argv[1] ;
  11.   char    *outfile = argv[2] ;
  12.   char    inline[MAXLINE] ;
  13.   char    outline[MAXLINE] ;
  14.   char    *s ,
  15.     *os ;
  16.   char    ch ;
  17.   FILE    *ifp ,
  18.     *ofp ;
  19.   int    i ;
  20.   long    len ,
  21.     outcount = 0 ,
  22.     incount  = 0;
  23.  
  24.   if (argc != 3) {
  25.     printf ("Usage index <infile> <outfile>") ;
  26.     exit (1) ;
  27.   }
  28.  
  29.   if (!(ifp = fopen (infile,"br"))) {
  30.     printf ("unable to open infile %s\n",infile) ;
  31.     exit (2) ;
  32.   }
  33.  
  34.   if (!(ofp = fopen (outfile,"w"))) {
  35.     printf ("unable to open outfile %s\n") ;
  36.     fclose (ifp) ;
  37.     exit(3) ;
  38.   }
  39.  
  40.   while (len = fgets_ri(inline,MAXLINE,ifp)) {
  41.     if ((i = findex (inline,"---")) >= 0) {
  42.       *(os = outline) = ((s=inline)[i]) = '\0' ;
  43.       while (ch = *s) {
  44.     if (isupper(ch)) {
  45.       do {
  46.         ch = (*os++ = *s++) ;
  47.       } while (ch && ch != ' ' && ch != '\t') ;
  48.       s-- ;
  49.     }
  50.     s++ ;
  51.       }
  52.       os-- ;
  53.       while (ch = *os && (ch == ' ' || ch == '\t')) os-- ;
  54.       *os = '\0' ;
  55.  
  56.       if (*outline)  {
  57.     fprintf (ofp,"%06ld %s\n",incount,outline) ;
  58.     outcount += strlen(outline)+9 ;
  59.       }
  60.     }
  61.     incount += len ;
  62.   }
  63.   fprintf (ofp,"%06ld\n",outcount+8) ;
  64.   fclose(ifp) ;
  65.   fclose(ofp) ;
  66. }
  67.  
  68.  
  69. findex (s,t)
  70. REG char *t,*s;
  71. {
  72.  
  73.   REG int i,j,k;
  74.   REG char    ch;
  75.  
  76.   for (i=0;s[i] != '\0';i++) {
  77.     for (j=i,k=0;t[k] != '\0' && s[j] == t[k]; j++,k++);
  78.     if (t[k] == '\0') return (i);
  79.   }
  80.   return (-1);
  81. }
  82.  
  83. /*******
  84.   Im Unterschied zur Library_funktion fgets
  85.   liefert fgets_ri die Laenge der Eingabezeile zurueck
  86. */
  87. fgets_ri (s,ml,fp)
  88. register char    *s;
  89. register int    ml;
  90. FILE    *fp;
  91. {
  92.  
  93.   REG    int    ch,
  94.         i=0;
  95.  
  96.   while (i++<ml) {
  97.     if ((ch=getc(fp)) == EOF) {
  98.       i--;
  99.       break;
  100.     }
  101.     if ((*s++=ch) == '\n' || ch == '\r') break;
  102.   }
  103.   *s = '\0';
  104.   return (i);
  105. }
  106.